package gui.win.barcode;

import core.utils.Utils;
import gui.Segl1;
import gui.processor.Processor;
import gui.processor.Worker;
import gui.utils.Para;
import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JButton;
import javax.swing.JPanel;

/*Author: John Archer, Contact: john.archer.jpa@gmail.com*/
public class Buttons extends JPanel implements ActionListener{
    private JButton close, process;
    private BarCodes barCodes;
    private Segl1 segL1;
    public Buttons(BarCodes barCodes, Segl1 segL1){
        super(new BorderLayout());
        this.barCodes = barCodes;
        this.segL1 = segL1;
        this.add(Utils.getButton(close = new JButton("CANCEL"), 184, 22, new Color(102, 102, 102), new Color(178, 178, 178), this, "CANCEL"), BorderLayout.WEST);
        this.add(Utils.getButton(process = new JButton("PROCESS"), 184, 22, new Color(102, 102, 102), new Color(178, 178, 178), this, "PROCESS"), BorderLayout.EAST);
    }
    
    public void actionPerformed(ActionEvent evt) {
        Object source = evt.getSource(); 
        if(source == close){barCodes.dispose();}
        else if(source == process){
            Para.UNSORT = barCodes.getPathToReads();
            Para.BARCODES = barCodes.getPathToBarcodes();
            Processor processor = new Processor(segL1);
            processor.setTask(Para.TASK_BARCODES);
            Worker sl = new Worker(processor);
            sl.execute();
            barCodes.dispose();
        }
    }
    public void closeFrame(){barCodes.dispose();}
}
